﻿using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;

namespace Bot.Domain
{
    public class APIHelper
    {
        public static ApiResult GenerateByCode(int iCode, object oData, bool bSuccess, object[] parameters = null)
        {
            return new ApiResult { Data = oData, IsSuccess = bSuccess, Error = GetErrorMessageByCode(iCode, parameters) };
        }
        public static ApiResult GenerateByErrorInfo(ErrorInfo errorInfo, object oData, bool bSuccess)
        {
            return new ApiResult { Data = oData, IsSuccess = bSuccess, Error = errorInfo };
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static ErrorInfo GetErrorMessageByCode(int code, object[] parameters = null)
        {
            #region 1 Success, no error info
            if (code == 1)
                return null;
            #endregion

            #region 50001 ~ 50200 Common
            if (code > 50000 && code < 50201)
                return GetCommomMessageByCode(code, parameters);
            #endregion

            #region 50201 ~ 51200 Bot
            if (code > 50200 && code < 51201)
                return GetBotMessageByCode(code, parameters);
            #endregion

            #region 51201 ~ 52200 Intent
            if (code > 51200 && code < 52201)
                return GetIntentMessageByCode(code, parameters);
            #endregion

            #region 52201 ~ 53200 Entity
            if (code > 52200 && code < 53201)
                return GetEntityMessageByCode(code, parameters);
            #endregion

            #region 53201 ~ 54200 Smart Trigger
            if (code > 53200 && code < 54201)
                return GetSmartTriggerMessageByCode(code, parameters);
            #endregion

            #region 54201 ~ 55200 Quick Reply
            if (code > 54200 && code < 55201)
                return GetQuickReplyMessageByCode(code, parameters);
            #endregion

            #region 55201 ~ 56200  Report
            if (code > 55200 && code < 56201)
                return GetReportMessageByCode(code, parameters);
            #endregion

            #region 57201 ~ 58200  Agent Bot
            if (code > 57200 && code < 58201)
                return GetAgentBotMessageDiceByCode(code, parameters);
            #endregion

            #region 58201 ~ 59200  Language
            if (code > 58200 && code < 59201)
                return GetLanguageMessageDiceByCode(code, parameters);
            #endregion

            return new ErrorInfo { Code = 50002, Message = "Request Parameter Error" };
        }

        static Dictionary<int, string> commomMessageDic = new Dictionary<int, string>() {
            { 50001,"500 - Internal Server Error" },
            { 50002,"Bad Request - Parameter Error" },
            { 50003,"Unauthorized request." },
            { 50004,"Request resource not found." },
            { 50005,"Request method not allowed." },
            { 50006,"Request time out." },
            { 50007,"Not implemented." },
            { 50008,"Bad gateway." },
            { 50009,"Bot service is unavailable." },
            { 50010,"Invalid file type." },
            { 50011,"No file selected." },
            { 50038,"Request parameter [languageCode] is required." },
            { 50039,"Request parameter [siteId] is required." },
            { 50040,"Request parameter [botId] is required." },
            { 50041,"Total monthly quota limit exceeded." },
            { 50042,"Site with ID {0} does not exist or the site has been closed." },
            { 50043,"Sign in required" },
            { 50044,"Bot service error." },
            { 50045,"Request parameter [type] is not supported." },
            { 50046,"Request parameter [languageCode] is not supported." },
            { 50047,"Request parameter [type] is required." },
            { 50048,"Language is not supported." },
            { 50049,"Bot not enabled for site {0}." },
            { 50050,"The file size should be less than 30MB." },
            { 50051,"Type can not be empty." },
            { 50052,"Url can not be empty." },
            { 50053,"Url cannot exceed 1280 characters." },
            { 50054,"Type only support visitorMessageSent, rateClicked, intentClicked, locationCollected, informationCollected." },
            { 50055,"The site have bot, can't create default bot." },
            { 50056,"Request parameter [include] cannot exceed 2000 characters." },
            { 50057,"Request parameter [keyword] cannot exceed 2000 characters." },
        };
        /// <summary>
        /// 50001 ~ 50200 Common
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetCommomMessageByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            commomMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }

        static Dictionary<int, string> botMessageDic = new Dictionary<int, string>() {
            { 50201,"You have not purchased bot yet." },
            { 50202,"There is no bot with Id {0} found." },
            { 50203,"Bot with the same name already exists." },
            { 50204,"The New Bot Request already exists." },
            { 50205,"Failed to create bot from chat transcript." },
            { 50206,"Failed to add category." },
            { 50207,"Failed to edit category." },
            { 50209,"Failed to edit bot." },
            { 50210,"Failed to delete bot." },
            { 50211,"Failed to add bot." },
            { 50212,"Failed to train bot." },
            { 50213,"To create a new bot, please submit a New Bot Request." },
            { 50214,"The bot with projectid {0} is already in use." },
            { 50215,"Category with the same name already exists." },
            { 50216,"Root category with the same name already exists in this bot." },
            { 50217,"Language with code {0} is not supported." },
            { 50218,"To create a new bot, please submit a New Bot Request." },
            { 50219,"The category parent Id should be greater than -1." },
            { 50220,"There is no bot category with ID {0}." },
            { 50221,"The bot with Id {0} does not contain a bot category with Id {1}." },
            { 50222,"The VisitorId should be greater than 0." },
            { 50223,"The SessionId cannot be empty or null." },
            { 50224,"The message cannot be empty or null." },
            { 50225,"The openIn type is not supported." },
            { 50226,"The channelType  is not supported." },
            { 50227,"The import xml detection don't pass.[error details: {0}]" },
            { 50228,"Restore bot data failed." },
            { 50229,"Extract operation state failed." },
            { 50230,"Mapping bot datafailed." },
            { 50231,"Queue bot data failed." },
            { 50232,"Delete bot data failed." },
            { 50233,"Save bot data failed." },
            { 50234,"Reset intent response failed." },
            { 50235,"The sessionId required."},
            { 50236,"The question required."},
            { 50237,"The chatId must be greater than 0."},
            { 50238,"The questionId required."},
            { 50239,"The senderId must be greater than 0."},
            { 50240,"The campaignId must be greater than 0."},
            { 50241,"The intent with id {0} does not exist."},
            { 50242,"The formValues required."},
            { 50243,"The lable of formValues required."},
            { 50244,"The value of formValues required."},
            { 50245,"The intentId not belong to the site."},
            { 50246,"The intentId not belong to the bot."},
            { 50247,"The Bot with id {0} does not exist."},
            { 50248,"The Bot with id {0} does not belong Site with id {1}."},
            { 50249,"Parameter [possibleResponsesThreshold] is required and must be greater than 0."},
            { 50250,"Parameter [highConfidenceScore] must be greater than Parameter[noAnswerScore]."},
            { 50251,"Parameter [highConfidenceScore] must between 1 and 100."},
            { 50252,"Parameter [noAnswerScore] must between 0 and 100."},
            { 50253,"Parameter [email] invalid."},
            { 50254,"Parameter [BotId] invalid."},
            { 50255,"Parameter [Id] invalid."},
            { 50256,"Bot is already trained."},
            { 50257,"Parameter [greetingMessage] does not support WebhookResponse."},
            { 50258,"The chat server service call failed."},
            { 50259,"Parameter [greetingMessage] cannot have more than 10 items in each channel."},
            { 50260,"Parameter [operationType] only support queryIntent,goToIntent,viaForm,signedIn,requestLocation or viaPrompts."},
            { 50261,"Parameter [channelType] only support default,livechat,facebook or twitter."},
            { 50262,"Engine can not be empty."},
            { 50263,"Engine only support comm100Bot, thirdPartyBot."},
            { 50264,"Third-party Bot does not support Category Management."},
            { 50265,"Third-party Bot does not support Entity Management."},
            { 50266,"Third-party Bot does not support Intent Management."},
            { 50267,"Third-party Bot does not support Quick Reply Management."},
            { 50268,"Third-party Bot does not support Smart Trigger Management."},
            { 50269,"Third-party Bot does not support Export Bot."},
            { 50270,"Third-party Bot does not support Import Bot."},
            { 50271,"Third-party Bot does not support Train Bot."},
            { 50272,"Third-party Bot does not support Test Bot."},
            { 50273,"Cannot create webhook unless it is a Third-party Bot."},
            { 50274,"Webhook with type [{0}] already exist."},
            { 50275,"Parameter [WebhookTargetUrl] cannot be empty."},
            { 50276,"Parameter {0} cannot be empty."},
            { 50277,"Third-party Bot does not support SendMessage."},
            { 50278,"Third-party Bot does not support Learning Question Management."},
            { 50279,"Parameter [WebhookTargetUrl] cannot exceed 1024 characters."},
            { 50280,"Parameter [Language] cannot be empty."},
            { 50281,"Parameter [questions] cannot be empty."},
            { 50282,"Parameter [channelType] cannot be empty."},
            { 50283,"Parameter [inclue] must be 'intent'."},
        };
        /// <summary>
        /// 50201 ~ 51200 Bot
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetBotMessageByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            botMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }

        static Dictionary<int, string> intentMessageDic = new Dictionary<int, string>() {
            { 51201,"Intent with the same name already exists." },
            { 51202,"Question with the same name already exists." },
            { 51203,"Learnning failed." },
            { 51204,"Failed to delete intent." },
            { 51205,"Failed to add intent." },
            { 51206,"Failed to edit intent." },
            { 51207,"Parameter[questions] cannot be empty." },
            { 51208,"Parameter[answer] cannot be empty." },
            { 51209,"Parameter[name] cannot be empty." },
            { 51210,"Parameter[name] cannot exceed 100 characters." },
            { 51211,"Parameter[name] cannot be default." },
            { 51212,"The number of items in each channel cannot exceed 10." },
            { 51213,"When Parameter[ifNeedSignIn] is true, Parameter [answerSignInSettings] cannot be empty." },
            { 51214,"When Parameter[ifNeedSignIn] is true, Parameter[answerSignInSettings.signInLinkText] cannot be empty." },
            { 51215,"When Parameter[ifNeedSignIn] is true, Parameter[answerSignInSettings.signInMessage] cannot be empty." },
            { 51216,"When Parameter[ifNeedSignIn] is true, Parameter[answerSignInSettings.signInURL] cannot be empty." },
            { 51217,"When Parameter[ifNeedSignIn] is true, Parameter[answerSignInSettings.signInLinkText] cannot exceed 128 characters." },
            { 51218,"When Parameter[ifNeedSignIn] is true, Parameter[answerSignInSettings.signInMessage] cannot exceed 1280 characters." },
            { 51219,"When Parameter[ifNeedSignIn] is true, Parameter[answerSignInSettings.signInURL] cannot exceed 1280 characters." },
            { 51220,"When Parameter[ifNeedSignIn] is true and Parameter[answerSignInSettings.isSSO] is false,Parameter[answerSignInSettings.openIn] is required and only supports currentWindow, newWindow and sideWindow." },
            { 51221,"When Parameter[type] is text, Parameter[textVariants] cannot be empty." },
            { 51222,"When Parameter[type] is text, the number of Parameter [textVariants] cannot exceed 10." },
            { 51223,"When Parameter[type] is text, item in Parameter [textVariants] cannot be empty." },
            { 51224,"When Parameter[type] is image, Parameter[image] cannot be empty." },
            { 51225,"When Parameter[type] is image, Parameter[image.name] cannot be empty." },
            { 51226,"When Parameter[type] is image, Parameter[image.id] cannot be empty." },
            { 51227,"When Parameter[type] is image, Parameter[image.name] cannot exceed 128 characters." },
            { 51228,"When Parameter[type] is image, Parameter[content.url] cannot exceed 1280 characters." },
            { 51229,"When Parameter[type] is video, Parameter[videoUrl] cannot be empty." },
            { 51230,"When Parameter[type] is video, Parameter[videoUrl.url] cannot be empty." },
            { 51231,"When Parameter[type] is video, Parameter[videoUrl] cannot exceed 512 characters." },
            { 51232,"When Parameter[type] is webhook, Parameter[webhook] cannot be empty." },
            { 51233,"When Parameter[type] is webhook, Parameter[webhook.url] cannot be empty." },
            { 51234,"When Parameter[type] is webhook, Parameter[webhook.url] cannot exceed 1024 characters." },
            { 51235,"When Parameter[type] is quickreply, Parameter[quickReply] cannot be empty." },
            { 51236,"When Parameter[type] is quickreply, Parameter[quickReply.name] cannot be empty." },
            { 51237,"When Parameter[type] is quickreply, Parameter[quickReply.name] cannot exceed 128 characters." },
            { 51238,"When Parameter[type] is quickreply, Parameter[quickReply.id] is required and must be greater than 0." },
            { 51239,"When Parameter[type] is button, Parameter[buttons] cannot be empty." },
            { 51240,"When Parameter[type] is button, Parameter[buttons.text] cannot be empty." },
            { 51241,"When Parameter[type] is button, Parameter[content.text] cannot exceed 4000 characters." },
            { 51242,"When Parameter[type] is button, Parameter[content.buttons] cannot be empty." },
            { 51243,"When Parameter[type] is button, the number of Parameter[content.buttons] cannot exceed 3 unless Parameter[answer]'s channel type is livechat." },
            { 51244,"When Parameter[type] is button, Parameter[buttons.openIn] is required and only supports currentWindow, newWindow and sideWindow." },
            { 51245,"When Parameter[type] is button, Parameter[content.buttons.openStyle] is required and only supports compact, full and tall." },
            { 51246,"When Parameter[type] is button, Parameter[buttons.type] is required and only supports triggerAnIntent, link and webView." },
            { 51247,"When Parameter[type] is button, Parameter[buttons.text] cannot be empty." },
            { 51248,"When Parameter[type] is button, Parameter[content.buttons.text] cannot exceed 20 characters unless Parameter[answer]'s channel type is livechat." },
            { 51249,"When Parameter[type] is button and Parameter[content.buttons.type] is goToIntent, Parameter[content.buttons.intentId] is required and must be greater than 0." },
           // { 51250,"When Parameter[type] is button and Parameter[buttonResponse.buttons.type] is goToIntent,Parameter[buttonResponse.buttons.intentName] cannot be empty." },
          //  { 51251,"When Parameter[type] is button and Parameter[buttonResponse.buttons.type] is goToIntent,the length of Parameter[buttonResponse.buttons.intentName] cannot exceed 100." },
            { 51252,"When Parameter[type] is button and Parameter[buttons.type] is link or webView, Parameter[buttons.Url] cannot be empty." },
            { 51253,"When Parameter[type] is button and Parameter[buttons.type] is link or webView, Parameter[buttons.Url] cannot exceed 512 characters." },
            { 51254,"The number of Parameter[questions] cannot exceed 2000." },
            { 51255,"Parameter[questions.text] cannot exceed 768 characters." },
            { 51256,"When Parameter[questions.entityLabels] is not empty, Parameter[questions.entityLabels.label] cannot be empty." },
            { 51257,"Parameter[questions.entityLabels.label] cannot exceed 30 characters." },
            { 51258,"Parameter[questions.entityLabels.label] can only start with a letter and contain the following:A-Z, a-z, 0-9, _ or -." },
            { 51259,"Parameter[questions.entityLabels.entityId] is required and must be greater than 0." },
            { 51260,"Parameter[questions.entityLabels.startPos] cannot be greater than Parameter[questions.entityLabels.endPos]." },
            { 51261,"When Parameter[ifRequireDetailInfo] is true, Parameter[EntityCollectionType] is required and only supports prompt and form." },
            { 51262,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, Parameter[entityCollectionPrompts] cannot be empty." },
            { 51263,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm] and Parameter[entityCollectionForm.formFields] cannot be empty." },
            { 51264,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formMessage] cannot be empty." },
            { 51265,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formTitle] cannot be empty." },
            { 51266,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formMessage] cannot exceed 1280 characters." },
            { 51267,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formTitle] cannot exceed 20 characters." },
            { 51268,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formFields.label] cannot be empty." },
            { 51269,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formFields.label] cannot exceed 30 characters." },
            { 51270,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formFields.label] can only start with a letter,end with a letter or a number and contain the following:A-Z, a-z, 0-9, _ or -." },
            { 51271,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formFields.entityId] is required and must be greater than 0" },
            { 51272,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, the number of Parameter[entityCollectionForm.formFields.option] cannot exceed 10." },
            { 51273,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, item in Parameter[entityCollectionForm.formFields.option] cannot be empty." },
            { 51274,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, item in Parameter[entityCollectionForm.formFields.option] cannot exceed 100 characters." },
            { 51275,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formFields.fieldType] is required and only supports text, textArea, radio, checkBox, checkBoxList and dropDownList." },
            { 51276,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formFields.fieldName] cannot be empty." },
            { 51277,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is form, Parameter[entityCollectionForm.formFields.fieldName] cannot exceed 128 characters." },
            { 51278,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, Parameter[entityCollectionPrompts.label] cannot be empty." },
            { 51279,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, Parameter[entityCollectionPrompts.label] cannot exceed 30 characters." },
            { 51280,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, Parameter[entityCollectionPrompts.label] can only start with a letter,end with a letter or a number and contain the following:A-Z, a-z, 0-9, _ or -." },
            { 51281,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, Parameter[entityCollectionPrompts.entityId] is required and must be greater than 0" },
            { 51282,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, the number of Parameter[entityCollectionPrompts.option] cannot exceed 10." },
            { 51283,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, item in Parameter[entityCollectionPrompts.option] cannot be empty." },
            { 51284,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, item in Parameter[entityCollectionPrompts.option] cannot exceed 20 characters." },
            { 51285,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, Parameter[entityCollectionPrompts.questions] cannot be empty." },
            { 51286,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, the number of Parameter[entityCollectionPrompts.questions] cannot exceed 30." },
            { 51287,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, item in Parameter[entityCollectionPrompts.questions] cannot be empty." },
            { 51288,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, item in Parameter[entityCollectionPrompts.questions] cannot exceed 768 characters." },
            { 51289,"Parameter[questionId] Not Found." },
            { 51290,"Parameter[chatId] Not Found." },
            { 51291,"Failed to delete the learning question." },
            { 51292,"Timezone format invalid,Timezone must fit the format [(±)HH:MM]." },
            { 51293,"Validtion check failed. Error details: [{0}]" },
            { 51294,"The engine delete failed." },
            { 51295,"The engine operation state extraction failed." },
            { 51296,"The data delete failed." },
            { 51297,"The category create failed." },
            { 51298,"The engine import failed." },
            { 51299,"The engine data mapping failed." },
            { 51300,"The data queuing failed." },
            { 51301,"The data saving failed." },
            { 51302,"The excel create failed." },
            { 51303,"Parameter[categoryId] is required and must be greater than 0." },
            { 51304,"Parameter[categoryId] with [{0}] does not exist." },
            { 51305,"Parameter[categoryId] with [{0}] does not belong to Site with id [{1}]." },
            { 51306,"Parameter[categoryId] with [{0}] does not belong to Bot with id [{1}]." },
            { 51307,"Parameter[questions.entityLabels.entityId] with [{0}] does not exist." },
            { 51308,"Parameter[questions.entityLabels.entityId] with [{0}] does not belong to Site with id [{1}]." },
            { 51309,"Parameter[questions.entityLabels.entityId] with [{0}] does not belong to Bot with id [{1}]." },
            { 51310,"Parameter[content.buttons.intentId] with [{0}] does not exist." },
            { 51311,"Parameter[content.buttons.intentId] with [{0}] does not belong to Site with id [{1}]." },
            { 51312,"Parameter[content.buttons.intentId] with [{0}] does not belong to Bot with id [{1}]." },
            { 51313,"Intent with Id [{0}] does not exist." },
            { 51314,"Intent with Id [{0}] does not belong to Site with id [{1}]." },
            { 51315,"Intent with Id [{0}] does not belong to Bot with id [{1}]." },
            { 51316,"Parameter[timeTo] must be greater than Parameter[timeFrom]." },
            { 51317,"Parameter[entityCollectionForm.formFields.entityId] with [{0}] does not exist." },
            { 51318,"Parameter[entityCollectionForm.formFields.entityId] with [{0}] does not belong to Site with id [{1}]." },
            { 51319,"Parameter[entityCollectionForm.formFields.entityId] with [{0}] does not belong to Bot with id [{1}]." },
            { 51320,"Parameter[entityCollectionPrompts.entityId] with [{0}]does not exist." },
            { 51321,"Parameter[entityCollectionPrompts.entityId] with [{0}] does not belong to Site with id [{1}]." },
            { 51322,"Parameter[entityCollectionPrompts.entityId] with [{0}] does not belong to Bot with id [{1}]." },
            { 51323,"The number of item whose [type] is quickReply cannot be greater than 1" },
            { 51324,"Parameter[content.quickReplyId] with [{0}] does not exist." },
            { 51325,"Parameter[content.quickReplyId] with [{0}] does not belong to Site with id [{1}]." },
            { 51326,"Parameter[content.quickReplyId] with [{0}] does not belong to Bot with id [{1}]." },
            { 51327,"Parameter[questions.entityLabels.label] with [{0}] cannot appear more than once in one question." },
            { 51328,"Parameter[questions.entityLabels.startPos] with [{0}] cannot between other entityLabel's Parameter[questions.entityLabels.startPos]  with [{1}] and Parameter[questions.entityLabels.endPos] with [{2}]." },
            { 51329,"Parameter[questions.entityLabels.endPos] with [{0}] cannot between other entityLabel's Parameter[questions.entityLabels.startPos]  with [{1}] and Parameter[questions.entityLabels.endPos] with [{2}]." },
            { 51330,"Parameter[questions.entityLabels.label] with [{0}] cannot appear more than once with different Parameter[questions.entityLabels.entityId]." },
            { 51331,"Parameter[entityCollectionForm.formFields.entityId] with [{0}] must be one of Parameter[questions.entityLabels.entityId]." },
            { 51332,"Parameter[entityCollectionPrompts.entityId] with [{0}] must be one of Parameter[questions.entityLabels.entityId]." },
            { 51333,"Parameter[entityCollectionForm.formFields.entityId] with [{0}] and Parameter[entityCollectionForm.formFields.label] with [{1}] must belong to one item in Parameter[questions.entityLabels]." },
            { 51334,"Parameter[entityCollectionPrompts.entityId] with [{0}] and Parameter[entityCollectionPrompts.label] with [{0}] must belong to one item in Parameter[questions.entityLabels]." },
            { 51335,"Parameter[questions.entityLabels.startPos] with [{0}] must be less than Parameter[questions.text]'s length with [{1}]." },
            { 51336,"Parameter[questions.entityLabels.endPos] with [{0}] cannot be greater than Parameter[questions.text]'s length with [{1}]." },
            { 51337,"Parameter[entityCollectionPrompts.label] with [{0}] cannot appear more than once." },
            { 51338,"Parameter[entityCollectionForm.formFields.label] with [{0}] cannot appear more than once." },
            { 51339,"Parameter[answer] cannot have more than one same channels." },
            { 51340,"Parameter[answer] only supports four channels as default,livechat,facebook and twitter." },
            { 51341,"Parameter[type] is required and only supports text,image,video,webhook,quickReply,button and complex." },
            { 51342,"When Parameter[type] is complex,Parameter[content.text] cannot be empty." },
            { 51343,"When Parameter[type] is complex,Parameter[message] cannot be empty." },
            { 51344,"Parameter[type] does not support complex unless updating object which already contain complex item." },
            { 51345,"The number of item whose [type] is complex cannot be greater than 1]" },
            { 51346,"Parameter[content.buttons.type] cannot be goToIntent unless Parameter[answer]'s channel type is livechat or facebook" },
            { 51347,"When Parameter[ifNeedSignIn] is true,Parameter[answerSignInSettings.customVariable] cannot exceed 128 characters." },
            { 51348,"This answer is ratting." },
            { 51349,"This answer is deleted." },
            { 51350,"Parameter[questions] cannot appear more than once with same text." },
            { 51351,"When Parameter[answer]'s channel type is default,Parameter[type] only support text,quickReply and button." },
            { 51352,"Parameter[type] does not support complex unless Parameter[answer]'s channel type is livechat." },
            { 51353,"Parameter[questions.text] is required." },
            { 51354,"When Parameter[ifRequireDetailInfo] is true,Parameter[questions.entityLabels] is required." },
            { 51355,"Parameter[responses] cannot be empty." },
            { 51356,"When Parameter[ifNeedSignIn] is true and Parameter[answerSignInSettings.isSSO] is false,Parameter[answerSignInSettings.customVariable] is required." },
            { 51357,"The maximum length of Parameter[Question] is 256." },
            { 51358,"Parameter[content.quickReplyId] must be a guid." },
            { 51359,"Parameter[content.buttons.intentId] must be a guid." },
            { 51360,"Parameter[content.buttons.openIn] only supports currentWindow,newWindow and sideWindow." },
            { 51361,"Parameter[content.buttons.openStyle] only supports compact,full and tall." },
            { 51362,"learningQuestionId with [{0}] does not exist." },
            { 51363,"When Parameter[type] is text, Item in Parameter[content.texts] cannot contain goToIntent info unless channel type is livechat" },
            { 51364,"When Parameter[type] is text, the total length of Parameter [content.texts] cannot exceed 4000." },
            { 51365,"When Parameter[ifRequireDetailInfo] is true and Parameter[entityCollectionType] is prompt, the total length of Parameter[entityCollectionPrompts.options] cannot exceed 1024." },
            { 51366,"Parameter[questions] cannot have more than 20 different entityLabels." },
            { 51367,"Parameter[questions.entityLabels.startPos] must greater than or equal to 0." },
            { 51368,"Parameter[questions.entityLabels.endPos] must greater than or equal to 0." },
            { 51369,"Parameter[answer] cannot be empty at intent name '{0}'." },
            { 51370,"Intent cannot be deleted. {0}" },
            { 51371,"Parameter[answer] must contains at least one item with responses." },
            { 51372,"When Parameter[type] is text and contain intent link, but the intent not exists." },
            { 51373,"learningQuestionId must comma-seprated numbers." },
            { 51374,"Another importing process is ongoing, please try again later." },
            { 51375,"Parameter[questions] cannot be empty." },
            { 51376,"The maximum length of single question is 256 ." },
            { 51377,"When Parameter[type] is button, Parameter[content.buttons.text] cannot exceed 128 characters when Parameter[answer]'s channel type is livechat." },
            { 51378,"The maximum number of imports is 100 ." },
            { 51379,"Only the comm100OwnBot support." },
            { 51380,"Parameter[question] cannot be empty." },
            { 51381,"When Parameter[type] is webhook, Parameter[content.headers] the dictionary key cannot be empty." },
            { 51382,"When Parameter[type] is webhook, Parameter[content.headers] the dictionary value cannot be empty." },
            { 51383,"When Parameter[type] is webhook, Parameter[content.headers] the dictionary cannot have the same key." },
            { 51384,"When Parameter[type] is webhook, Parameter[content.headers] the dictionary key length less than 4000." },
            { 51385,"When Parameter[type] is webhook, Parameter[content.headers] the dictionary value length less than 4000." },
            { 51386,"Parameter[answerInChannels.channel] cannot be empty." },
            { 51387,"When Parameter[answerInChannels.channel] cannot exceed 128 characters." },
            { 51388,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] cannot be empty." },
            { 51389,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] only supports SSO and customVariable." },
            { 51390,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] is SSO, Parameter[authenticationRequest.signInButtonText] cannot be empty." },
            { 51391,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] is SSO, Parameter[authenticationRequest.signInMessage] cannot be empty." },
            { 51392,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] is SSO, Parameter[authenticationRequest.signInURL] cannot be empty." },
            { 51393,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] is customVariable, Parameter[authenticationRequest.customVariable] cannot be empty." },
            { 51394,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] is SSO, Parameter[authenticationRequest.signInButtonText] cannot exceed 128 characters." },
            { 51395,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] is SSO, Parameter[authenticationRequest.signInMessage] cannot exceed 1280 characters." },
            { 51396,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] is SSO, Parameter[authenticationRequest.signInURL] cannot exceed 1280 characters." },
            { 51397,"When Parameter[answerInChannels.authenticationRequest] is not empty, Parameter[authenticationRequest.method] is customVariable, Parameter[authenticationRequest.customVariable] cannot exceed 128 characters." },
            { 51398,"When Parameter[answerInChannels.locationRequest] is not empty, Parameter[locationRequest.buttonText] cannot be empty." },
            { 51399,"When Parameter[answerInChannels.locationRequest] is not empty, Parameter[locationRequest.message] cannot be empty." },
            { 51400,"When Parameter[answerInChannels.locationRequest] is not empty, Parameter[locationRequest.buttonText] cannot exceed 1024 characters." },
            { 51401,"When Parameter[answerInChannels.locationRequest] is not empty, Parameter[locationRequest.message] cannot exceed 1024 characters." },
            { 51402,"When Parameter[type] is quickreply, Parameter[responses.message] cannot exceed 1024 characters." },
            { 51403,"Parameter[questions.id] is not exists, they are [{0}]." },
            { 51404,"Parameter[questions.selectedKeywords.id] is not exists, they are [{0}]." },
            { 51405,"Parameter[answerInChannels.id] is not exists, they are [{0}]." },
            { 51406,"Parameter[answerInChannels.authenticationRequest.id] is not exists, they are [{0}]." },
            { 51407,"Parameter[answerInChannels.locationRequest.id] is not exists, they are [{0}]." },
            { 51408,"Parameter[answerInChannels.form.id] is not exists, they are [{0}]." },
            { 51409,"Parameter[answerInChannels.form.fields.id] is not exists, they are [{0}]." },
            { 51410,"Parameter[answerInChannels.prompts.id] is not exists, they are [{0}]." },
            { 51411,"Parameter[answerInChannels.responses.id] is not exists, they are [{0}]." },
        };
        /// <summary>
        /// 51201 ~ 52200 Intent
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetIntentMessageByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            intentMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }

        static Dictionary<int, string> entityMessageDic = new Dictionary<int, string>() {
            { 52201,"Entity with the same name already exists." },
            { 52202,"Cannot delete Entity with Id [{0}], this Entity is in use." },
            { 52203,"Intent not found." },
            { 52204,"Failed to delete entity." },
            { 52205,"Parameter[name] cannot be empty." },
            { 52206,"Parameter[name] cannot exceed 30 characters." },
            { 52207,"Parameter[name] cannot be default." },
            { 52208,"Parameter[name] can only start with a letter,end with a letter or a number and contain the following:A-Z, a-z, 0-9, _ or -." },
            { 52209,"Parameter[keywords.keyword] cannot be empty" },
            { 52210,"Parameter[keywords.keyword] cannot exceed 128 characters." },
            { 52211,"Parameter[keywords.keyword] cannot start with/end with _(underscore)" },
            { 52212,"Parameter[keywords.keyword] cannot start with @" },
            { 52213,"Parameter[keywords.keyword] cannot contain \\, <, >, ^, (, ), |, *_, _*, &_ or _&." },
            { 52214,"{ and } must appear in pairs and contain characters in Parameter[keywords.keyword]" },
            { 52215,"[ and ] must appear in pairs and contain characters in Parameter[keywords.keyword]" },
            { 52216,"\" and \" must appear in pairs and contain characters in Parameter[keywords.keyword]" },
            { 52217,"Item in Parameter[keywords.synonyms] cannot be empty." },
            { 52218,"Item in Parameter[keywords.synonyms] cannot exceed 128 characters." },
            { 52219,"Item in Parameter[keywords.synonyms] cannot start with/end with _(underscore)" },
            { 52220,"Item in Parameter[keywords.synonyms] cannot start with @" },
            { 52221,"Item in Parameter[keywords.synonyms] cannot contain \\, <, >, ^, (, ), |, *_, _* ,&_ or _&." },
            { 52222,"{ and } must appear in pairs and contain characters in item of Parameter[keywords.synonyms]" },
            { 52223,"[ and ] must appear in pairs and contain characters in item of Parameter[keywords.synonyms]" },
            { 52224,"\" and \" must appear in pairs and contain characters in item of Parameter[keywords.synonyms]" },
            { 52225,"The total length of Parameter[keywords.synonyms] and Parameter[keywords.keyword] cannot exceed 4000." },
            { 52226,"Validtion check failed. Error details: [{0}]" },
            { 52227,"The engine import failed." },
            { 52228,"The engine operation state extraction failed." },
            { 52229,"The engine data mapping failed." },
            { 52230,"The data queuing failed." },
            { 52231,"The data saving failed." },
            { 52232,"The excel create failed." },
            { 52233,"Entity with Id [{0}] does not exist." },
            { 52234,"Entity with Id [{0}] does not belong to Site with id [{1}]." },
            { 52235,"Entity with Id [{0}] does not belong to Bot with id [{1}]." },
            { 52236,"Parameter[type] is required and only support entity." },
            { 52237,"Item in Parameter[keywords.synonyms] cannot contain comma(,)" },
            { 52238,"At least one keyword is required." },
            { 52239,"Parameter[keywords.keyword] cannot appear more than once." },
            { 52240,"Entity whose type is systemEntity is not allowed to delete." },
            { 52241,"Entity whose type is systemEntity is not allowed to update." },
            { 52242,"Cannot rename Entity with Id [{0}],this Entity is in use." },
            { 52243,"The number of entities exceeds the limitation 249." },
        };
        /// <summary>
        /// 52201 ~ 53200 Entity
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetEntityMessageByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            entityMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }

        static Dictionary<int, string> smartTriggerMessageDic = new Dictionary<int, string>() {
            { 53201,"Smart trigger with the same name already exists." },
            { 53202,"When parameter [conditions.when] is expression, parameter [conditions.expression] cannot be empty or null." },
            { 53203,"The parameter[conditions.expression] {0} is not supported." },
            { 53204,"The parameter[conditions.Items.variable] {0} is not supported." },
            { 53205,"The parameter[conditions.Items.expression] {0} is not supported." },
            { 53206,"The item of parameter[conditions.Items.Items] value {0} is not supported." },
            { 53207,"When parameter [actions.type] is segment,the parameter [actions.target.visitorSegmentId] needs to be greater than 0." },
            { 53208,"When parameter [actions.type] is {0}, parameter [actions.target.{1}] cannot be null and only allows one value." },
            { 53209,"Parameter [actions.{0}] is not supported." },
            { 53210,"There is no smart trigger with ID {0} found." },
            { 53211,"The item of parameter[conditions.Items.Items] value {0} is not supported." },
            { 53212,"The parameter[conditions.variable] {0} is not supported." },
            { 53213,"When the value of parameter [conditions.items[{2}].variable] is {0}, the value of parameter [conditions.items[{2}].expression] cannot be {1}." },
            { 53214,"When the parameter [actions.type] is monitor and transfer, their parameter [actions.isEnable] can not set true at the same time." },
            { 53215,"The parameter[actions.target.{0}] can not be null." },
            { 53216,"All smart triggers must be sorted by priority. " },
            { 53217,"The parameter[position]  needs to be greater than 0." },
            { 53218,"The parameter[conditions.Items[{0}].Items] cannot be null." },
            { 53219,"Do not set the same type of parameter[actions.type]." },
            { 53220,"The parameter[actions.agentOfflineMessage] cannot be empty or null." },
            { 53221,"The parameter[position] cannot have the same value." },
            { 53222,"The parameter[Target.Type] is required." },
            { 53223,"The parameter[Items] length is too long." },
            { 53224,"conditions.items[{0}].items[{1}] value is wrong." }
        };

        /// <summary>
        /// 53201 ~ 54200 Smart Trigger
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetSmartTriggerMessageByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            smartTriggerMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }

        static Dictionary<int, string> quickReplyMessageDic = new Dictionary<int, string>() {
            { 54201,"Quick reply with the same name already exists." },
            { 54202,"The maximum number of quick reply item is 10." },
            { 54203,"The maximum number of Contact Agent quick reply items is 1." },
            { 54204,"Quick Reply Go to Intent error: Item name or intent ID is required." },
            { 54205,"There is no quick reply with ID {0} found." },
            { 54206,"Quick Reply Go to Intent error: Intent doesn't exist." },
            { 54207,"Quick Reply item type only support 'triggerAnIntent' and 'contactAgent'." },
            { 54208,"The quick reply has been used in Intent or Bot's Greeting Message, cannot be deleted." },
            { 54209,"The name of quick reply item length less than 1280." },
            { 54210,"There is no quick reply item with ID {0} found." },
            { 54211,"Quick Reply type only support 'custom' and 'canned'." },
        };
        /// <summary>
        /// 54201 ~ 55200 Quick Reply
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetQuickReplyMessageByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            quickReplyMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }

        static Dictionary<int, string> reportMessageDic = new Dictionary<int, string>(){
            { 55201,"Invalid timezone format: Timezone is required and must be in the form of [(±)HH:MM]." },
            { 55202,"TimeTo should be larger than timeFrom." },
            { 55203,"You can only query data within one year." },
            { 55204,"The reportType is not supported." },
            { 55205,"The parameter[FilterType] value is not supported." },
            { 55206,"The parameter[DimensionType] value is not supported." },
            { 55207,"The parameter[FilterValue] value is wrong." },
            { 55208,"The parameter[FilterValue] cannot be empty or null." },
            { 55209,"Timezone must between 14:00 and -12:00." },
            { 55210,"The maximum value of PageSize is 100." },
            { 55211,"The parameter[DateRange] cannot be empty or null" },
            { 55212,"The parameter[DateRange] value is not supported." },
            { 55213,"The parameter[DateRange] is custom then timeFrom and timeTo cannot be empty or null." },
            { 55214,"The parameter[Page] cannot be empty or null." },
            { 55215,"The parameter[PageSize] cannot be empty or null." },
            { 55216,"The parameter[TimeFrom] cannot be empty or null." },
            { 55217,"The parameter[TimeTo] cannot be empty or null." },
            { 55218,"The parameter[DisplayBy] cannot be empty or null." },
            { 55219,"The parameter[DisplayBy] value is not supported." },
            { 55220,"Third-party Bot does not support SendMessage."},
            { 55221,"The parameter[Channel] cannot be empty or null." },
        };
        /// <summary>
        /// 55201 ~ 56200  Report
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetReportMessageByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            reportMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }
        /// <summary>
        /// 57201 ~ 58200  Agent Bot
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static Dictionary<int, string> agentBotMessageDic = new Dictionary<int, string>(){
            //agent bot setting
            { 57201,"Request parameter [language] is required." },
            { 57202,"Request parameter [highConfidenceScore] invalid." },
            { 57203,"Request parameter [maximumSuggestionNumber] invalid." },
            { 57204,"Agent Bot with the same siteId already exists." },
            { 57205,"Agent Bot with the siteId not exists." },
            { 57206,"Agent Bot language supported '{0}' ." },
            { 57207,"Request parameter [ifEnable] is required." },
            { 57208,"Request parameter [ifIncludeCannedMessage] is required." },
            { 57209,"Request parameter [ifIncludeKnowledgeBase] is required." },
            { 57210,"Request parameter [ifIncludeAiChatBot] is required." },
            { 57211,"Request parameter [ifAddSimilarQuestion] is required." },
            { 57212,"Request parameter [highConfidenceScore] is required." },
            { 57213,"Request parameter [maximumSuggestionNumber] is required." },
            { 57214,"You have not purchased agent bot yet." },

            //agent bot word weight
            { 57301,"Agent Bot Word Weight with the siteId not exists." },
            { 57302,"Agent Bot Word Weight with the same siteId already exists." },
            { 57303,"Request parameter [weight] invalid." },
            { 57304,"Request parameter [word] cannot contain the ':' character." },
            { 57305,"Request parameter [word] is required." },

            //agent bot synonym
            { 57401,"Agent Bot Synonym with the id not exists." },
            { 57402,"Agent Bot Synonym with the same keyword already exists." },
            { 57403,"Agent Bot Synonym with the same synonym [{0}] already exists." },
            { 57404,"Request parameter [keyword] is required." },
            { 57405,"Bad Request - Parameter Error." },
            { 57406,"Request parameter [keyword] already exists in the parameter [synonym]." },
            { 57407,"Failed to delete Synonym." },
            { 57408,"Request parameter [Synonym] cannot exceed 128 characters." },
            { 57409,"Request parameter [Synonym] cannot contain the ',' character. " },
            { 57410,"Request parameter [keyword] cannot exceed 512 characters. " },

            //agent bot learning
            { 57501,"Bad Request - Parameter Error." },
            { 57502,"Request parameter [type] is required." },
            { 57503,"Request parameter [question] is required." },
            { 57504,"Request parameter [question] cannot exceed 1024." },
            { 57505,"Request parameter [suggestionType] is required." },
            { 57506,"Request parameter [suggestionType] is cannedMessage,knowledgeBase or aiChatBot." },
            { 57507,"Request parameter [suggestionContent] is required." },
            { 57508,"Request parameter [suggestionType] is cannedMessage, parameter [SuggestionContent] must contain id field and is required." },
            { 57509,"Request parameter [suggestionType] is cannedMessage, parameter [SuggestionContent] contain id field is must number." },
            { 57510,"Request parameter [suggestionType] is cannedMessage, parameter [SuggestionContent] must contain title field and is required." },
            { 57511,"Request parameter [suggestionType] is cannedMessage, parameter [SuggestionContent] contain title field cannot exceed 1024." },
            { 57512,"Request parameter [suggestionType] is knowledgeBase, parameter [SuggestionContent] must contain id field and is required." },
            { 57513,"Request parameter [suggestionType] is knowledgeBase, parameter [SuggestionContent] contain id field is must number." },
            { 57514,"Request parameter [suggestionType] is knowledgeBase, parameter [SuggestionContent] must contain title field and is required." },
            { 57515,"Request parameter [suggestionType] is knowledgeBase, parameter [SuggestionContent] contain title field cannot exceed 1024." },
            { 57516,"Request parameter [suggestionType] is knowledgeBase, parameter [SuggestionContent] must contain articleId field and is required." },
            { 57517,"Request parameter [suggestionType] is knowledgeBase, parameter [SuggestionContent] contain articleId field is must number." },
            { 57518,"Request parameter [suggestionType] is aiChatBot, parameter [SuggestionContent] must contain id field and is required." },
            { 57519,"Request parameter [suggestionType] is aiChatBot, parameter [SuggestionContent] contain id field is must number." },
            { 57520,"Request parameter [suggestionType] is aiChatBot, parameter [SuggestionContent] must contain intentName field and is required." },
            { 57521,"Request parameter [suggestionType] is aiChatBot, parameter [SuggestionContent] contain intentName field cannot exceed 1024." },
            { 57522,"Request parameter [suggestionType] is aiChatBot, parameter [SuggestionContent] must contain intentId field and is required." },
            { 57523,"Request parameter [suggestionType] is aiChatBot, parameter [SuggestionContent] contain intentId field is must number." },
            { 57524,"Agent Bot Learning with the same question already exists." },
            { 57525,"Agent Bot Learning with the id not exists." },
            { 57526,"Failed to delete Learning." },
            { 57527,"Request parameter [type] is identified or unidentified." },

            { 57601,"Request parameter [id] is required." },
            { 57602,"Request parameter [question] is required." },
        };
        /// <summary>
        /// 57201 ~ 58200  AgentBot
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetAgentBotMessageDiceByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            agentBotMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }
        /// <summary>
        /// 58201 ~ 59200  Language
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static Dictionary<int, string> languageMessageDic = new Dictionary<int, string>(){
            //agent bot setting
            { 58201,"Language with the same code already exists." },
            { 58202,"Language with the same name already exists." },
            { 58203,"Request parameter [code] is required." },
            { 58204,"Request parameter [name] is required." },
            { 58205,"The maximum length of Parameter[code] is 64." },
            { 58206,"The maximum length of Parameter[name] is 256." },
            { 58207,"Failed to delete Language." },

        };
        /// <summary>
        /// 58201 ~ 59200  Language
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        static ErrorInfo GetLanguageMessageDiceByCode(int code, object[] parameters = null)
        {
            ErrorInfo error = new ErrorInfo { Code = code };
            string message = string.Empty;
            languageMessageDic.TryGetValue(code, out message);
            error.Message = message;
            if (parameters != null && !string.IsNullOrWhiteSpace(error.Message))
            {
                error.Message = string.Format(error.Message, parameters);
            }
            return error;
        }
    }
    public static class ExtentionUtils
    {
        public static T ToNullableObject<T>(this JObject obj)
        {
            try
            {
                return obj.ToObject<T>();
            }
            catch
            {
                return default(T);
            }
        }
        public static List<T> ToNullableObjectList<T>(this JArray arr)
        {
            List<T> tList = new List<T> { };
            try
            {
                if (arr != null)
                {
                    foreach(var item in arr)
                    {
                        tList.Add(ToNullableObject<T>(item as JObject));
                    }
                }
                return tList;
            }
            catch
            {
                return tList;
            }
        }
        /// <summary>
        /// char1 和char2 是一对字符，比如{} ，[] 等
        /// </summary>
        /// <param name="value"></param>
        /// <param name="char1"></param>
        /// <param name="char2"></param>
        /// <returns></returns>
        public static bool CheckSpecialCharacter(this string value, char char1, char char2)
        {
            if (char1 == char2)
            {
                int count = value.ToCharArray().Where(w => w == char1).Count();
                if (count % 2 != 0) return false;
                if (value.Contains(string.Format("{0}{1}", char1, char2))) return false;
                return true;
            }
            if (value.Contains(char1) && !value.Contains(char2)) return false;
            if (!value.Contains(char1) && value.Contains(char2)) return false;
            if (!value.Contains(char1) && !value.Contains(char2)) return true;
            if (value.IndexOf(char1) > value.IndexOf(char2)) return false;
            Stack<char> stack = new Stack<char>();
            string temp = string.Empty;
            List<string> content = new List<string>();
            bool beginRec = false;
            foreach (char i in value.ToCharArray())
            {
                if (i == char1)
                {
                    stack.Push(i);
                    if (!beginRec)
                    {
                        beginRec = true;
                    }
                    else
                    {
                        temp = string.Empty;
                    }
                    continue;
                }
                else if (i == char2)
                {
                    if (stack.Count <= 0)
                    {
                        return false;
                    }
                    stack.Pop();
                    content.Add(temp);
                    temp = string.Empty;
                    beginRec = false;
                }
                else if (beginRec)
                {
                    temp += i;
                }
            }
            if (stack.Count > 0) return false;
            if (content.Count <= 0 || content.Where(w => string.IsNullOrWhiteSpace(w)).Count() > 0) return false;
            return true;
        }
    }
}
